﻿/*
 
Celerity: Sensory Overload
Copright 2012 by Adam Hill, David Gannon, Thomas Tamblyn & Patrick Ytting
Contact: adam.hill@outlook.com
Website: adamhill.org
Licence: MS-Pl Licence
  
 */

using Celerity.Data;
using Celerity.Entities;
using Celerity.UI.Definition.Controls;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Celerity.UI.Definition
{
    public class UIControlHierarchy
    {
        UIGeometry geom;
        public List<UIEntity> Items { get; set; }

        public void Load(UIGeometry geom)
        {
            this.geom = geom;
            CreateHierarchy();
        }

        public void Update(IEnumerable<Vector2> interactions)
        {
            for (int i = 0; i < Items.Count(); i++)
            {
                Items[i].Update(interactions);
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            for (int i = 0; i < Items.Count(); i++)
            {
                Items[i].Draw(spriteBatch);
            }
        }

        void CreateHierarchy()
        {
            Items = new List<UIEntity>(100);
            for (int i = 0; i < Enum.GetValues(typeof(UIControl)).Length; i++)
            {
                Items.Add(GetEntity(i));
            };
        }

        UIEntity GetEntity(int i)
        {
            UIEntity entity;
            var control = (UIControl)i;
            switch (control)
            {
                case UIControl.UI:
                case UIControl.TL:
                case UIControl.TR:
                    entity = new UIEntity();
                    break;
                case UIControl.IconBack:
                    entity = new IconBackControl();
                    break;
                case UIControl.RedundantPleaseRecycleMe:
                    entity = new UIEntity();
                    break;
                case UIControl.IconMute:
                    entity = new IconMuteControl();
                    break;
                case UIControl.AboutDevs:
                    entity = new AboutDevsControl();
                    break;
                case UIControl.IconClose:
                    entity = new IconCloseControl();
                    break;
                case UIControl.PanelStart:
                    entity = new PanelStartControl();
                    break;
                case UIControl.RedundantPleaseRecycleMe2:
                    entity = new UIEntity();
                    break;
                case UIControl.ControlStatuses:
                    entity = new ControlStatusesControl();
                    break;
                case UIControl.RedundantPleaseRecycleMe3:
                    entity = new UIEntity();
                    break;
                case UIControl.RedundantPleaseRecycleMe4:
                    entity = new UIEntity();
                    break;
                case UIControl.PopupNoWebcam:
                    entity = new PopupNoWebcamControl();
                    break;
                case UIControl.PopupGameOver:
                    entity = new PopupGameOverControl();
                    break;
                case UIControl.PopupInstructions:
                    entity = new PopupInstructionsControl();
                    break;
                case UIControl.PopupAboutDevs:
                    entity = new PopupAboutDevsControl();
                    break;
                case UIControl.AboutPageTitle:
                    entity = new AboutPageTitleControl();
                    break;
                case UIControl.Logo:
                    entity = new LogoControl();
                    break;
                case UIControl.PopupCalibrator:
                    entity = new PopupCalibratorControl();
                    break;
                case UIControl.PopupCameraFps:
                    entity = new PopupCameraFpsControl();
                    break;
                case UIControl.PopupCameraFpsFast:
                    entity = new PopupCameraFpsFastControl();
                    break;
                case UIControl.PopupCameraFpsSlow:
                    entity = new PopupCameraFpsSlowControl();
                    break;
                case UIControl.PopupCameraFpsOverride:
                    entity = new CameraFpsOverrideControl();
                    break;
                case UIControl.IconBomb:
                    entity = new IconBombControl();
                    break;
                case UIControl.IconHeart:
                    entity = new IconHeartControl();
                    break;
                case UIControl.InGameScore:
                    entity = new InGameScoreControl();
                    break;
                default:
                    throw new KeyNotFoundException("UIControlHierarchy.GetEntity is missing the correct control");
            }
            entity.Offset = geom.Offsets[i];
            entity.Size = geom.Sizes[i];
            entity.ConfigureSelf();
            return entity;
        }
    }
}